package waitNotifyDemo;

public class Product extends Thread{


    @Override
    public void run() {
        while (true) {
            synchronized (StatusControl.lock) {
                try {
                    //判断共享数据是否到了末尾
                    if (StatusControl.total == 0) {
                        break;
                    }
                    //判断是否有数据，有就消费
                    if (StatusControl.status == 0) {

                        System.out.println("制作一碗");
                        //创建消息完之后，唤醒消费者者
                        StatusControl.lock.notify();
                        //修改状态
                        StatusControl.status = 1;
                    } else {
                        //还有数据就等待
                        StatusControl.lock.wait();
                    }
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }

    }
}
